package com.example.lirisheng.springbootfinalexperiment.util;


import com.example.lirisheng.springbootfinalexperiment.entity.UserRole;
import org.apache.catalina.User;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.List;
import java.util.stream.Collectors;

public class GeneralUtil {



    public static RespBean validateError(BindingResult result){
        if(result.hasErrors()){
            List<FieldError>  errors = result.getFieldErrors();
            List<String> stringErrors =  errors.stream().map(e->e.getDefaultMessage()).collect(Collectors.toList());
            return RespBean.error(stringErrors.get(0));
        }
        return null;
    }

    public  static void setUserRoleForUsers(List<UserRole> userRoles,Long userId){

        UserRole userRole = new UserRole();
        userRole.setRole(1L);
        userRole.setUser(userId);

    }

    public  static void setCHECKRoleForUser(List<UserRole> userRoles,Long userId){

        UserRole userRole = new UserRole();
        userRole.setRole(2L);
        userRole.setUser(userId);


    }
}
